package com.javaGame.frame;

import com.javaGame.util.SortBean;
import com.javaGame.util.SortPress;
import com.javaGame.util.TextLabel;

import javax.swing.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.List;

/**
 * 排行榜
 */
public class SortFrame extends JFrame implements KeyListener {
    public SortFrame(){
        this.setLayout(null);

        showInfo();
        new ImageLabel("image/sort.png",0,0,
                1000,700,this);



        //注册键盘事件
        this.addKeyListener(this);

        this.setSize(1000,700);
        this.setVisible(true);
        this.setDefaultCloseOperation(3);
        this.setLocationRelativeTo(null);
    }

    /**
     * 显示排行榜内容
     */
    private void showInfo() {
        SortPress press = new SortPress();
        List<SortBean> list = press.read();

        for(int i=0;i<list.size();i++){
            SortBean sortBean = list.get(i);
            new TextLabel(sortBean.getPlayName(),300,100+i*50,this);
            new TextLabel(sortBean.getPointer()+"",700,100+i*50,this);
        }
    }

    @Override
    public void keyTyped(KeyEvent e) {}

    @Override
    public void keyPressed(KeyEvent e) { }

    @Override
    public void keyReleased(KeyEvent e) {
        int keyCode = e.getKeyCode();
        if(keyCode == KeyEvent.VK_ESCAPE){
            this.dispose();
            new MenuFrame();
        }
    }

    public static void main(String[] args) {
        new SortFrame();
    }
}
